﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Samples.Location;
using foursquare.Forms;
using foursquare.Foursquare;
using foursquare.Location;

namespace foursquare
{
    public partial class CheckinView : Form
    {

        private double _geolat;
        private double _geolong;

        public CheckinView(double lat, double geolong)
        {
            InitializeComponent();

            _geolat = lat;
            _geolong = geolong;

            updateVenues();

            //try
            //{
            //    showTips();
            //}
            //catch { }
        }

        private void showTips()
        {
            List<Tip> tips = FS.GetTips(_geolat, _geolong, 0);
            foreach (Tip t in tips)
            {
                TipPanel tp = new TipPanel(t);
                tp.Dock = DockStyle.Bottom;
                this.Controls.Add(tp);
            }
        }

        private void updateVenues()
        {

            // Get Venues
            List<Venue> venues = FS.GetVenues(_geolat, _geolong);
            cbxVenues.DataSource = venues;
            cbxVenues.DisplayMember = "name";
            cbxVenues.ValueMember = "id";
        }

        private void mnuCancel_Click(object sender, EventArgs e)
        {
            Close();
        }


        private void cbxVenues_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxVenues.SelectedValue != null)
            {
                //int vid = Convert.ToInt32(cbxVenues.SelectedValue);
                //Venue v = FS.GetVenue(vid);
                //TODO: show venue info.
            }
        }

        private void mnuCheckInVenue_Click(object sender, EventArgs e)
        {
            //GeoLocation position = GetLocation();

            int vid = Convert.ToInt32(cbxVenues.SelectedValue);
            string shout = txtShout.Text;

            try
            {
                string response = FS.VenueCheckin(vid, String.Empty, shout, 0, 0, _geolat, _geolong);
                MessageBox.Show(response, this.Text);
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text);
            }
        }

        private void mnuAddVenue_Click(object sender, EventArgs e)
        {
            AddVenueView view = new AddVenueView();
            view.Show();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            int vid = Convert.ToInt32(cbxVenues.SelectedValue);
            AddTipView view = new AddTipView(vid);
            view.Show();
        }
    }
}